package com.grammer.thread;

import java.util.concurrent.*;

public class ThreadExceptionDemo {


    public static void main(String[] args) {
        if(true){
            System.out.println("正确返回调用");
        }
        ExecutorService executor = Executors.newSingleThreadExecutor();
        Future<Void> future = executor.submit(new Callable<Void>() {
            @Override
            public Void call()  throws Exception{

                System.out.println("** Started");
                //throw new IllegalStateException("exception from thread");
                Thread.sleep(10000);
                return null;
            }
        });

        try {
            future.get(); // raises ExecutionException for any uncaught exception in child
        } catch (ExecutionException | InterruptedException e) {
            System.out.println("** RuntimeException from thread ");
        }

        executor.shutdown();
        System.out.println("** Main stopped");
    }

}